package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.AddMicroProductBean;
import com.ymatou.iapi.productmanager.service.AddMicroProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.AddProductCallServiceV2;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.ArrayList;
import java.util.List;
/**
*发布微店商品
*FreeMaker Template自动生成代码
*/
@Ignore
@TestSuite
public class Ts_AddMicroProduct{
	private static AddMicroProductBean addmicroproductBean;
	private static AddMicroProductCall addmicroproductCall;
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发布微店商品");
	}

	@Before
	public void caseUp() {
		addmicroproductBean=new AddMicroProductBean();
		addmicroproductCall=new AddMicroProductCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(addmicroproductCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_001() {
		Logger.start(true,"发布微店普通商品，多规格，成功");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();			
			Logger.verifyEquals("200", addmicroproductCall.getString("Code"), "验证Code");
			String productId = addmicroproductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
			AddProductCallServiceV2.checkAddMicroProduct(productId,addMicroProductBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_002() {
		Logger.start(true,"发布微店普通商品，单规格，成功");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().getCatalogList().remove(0);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("200", addmicroproductCall.getString("Code"), "验证Code");
			String productId = addmicroproductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
			AddProductCallServiceV2.checkAddMicroProduct(productId,addMicroProductBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_003() {
		Logger.start(true,"参数校验-发布微店普通商品，买手id为0");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(0);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("400", addmicroproductCall.getString("Code"), "买手Id不能为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_004() {
		Logger.start(true,"参数校验-发布微店普通商品，买手不存在");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(8327);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "发布商品无对应的卖家信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_005() {
		Logger.start(true,"参数校验-发布微店普通商品，商品二级类目为空，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setSecondCategoryId(0);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("400", addmicroproductCall.getString("Code"), "二级类目Id格式错误");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_006() {
		Logger.start(true,"参数校验-发布微店普通商品，商品一级类目为空，发布成功，根据二级类目补齐");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setFirstCategoryId(0);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("200", addmicroproductCall.getString("Code"), "根据二级类目补全");
			String productId = addmicroproductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
			AddProductCallServiceV2.checkAddMicroProduct(productId,addMicroProductBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_007() {
		Logger.start(true,"参数校验-规格缺失，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setCatalogList(null);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "商品或规格数据缺失");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_008() {
		Logger.start(true,"参数校验-商品数据缺失，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.setProduct(null);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("400", addmicroproductCall.getString("Code"), "参数错误");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_009() {
		Logger.start(true,"参数校验-主图重复");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			List<String> picUrls = new ArrayList<>();
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			addMicroProductBean.getProduct().setPicUrls(picUrls);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "主图中含有重复的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_addMicroProduct_010() {
		Logger.start(true,"参数校验-文描图重复");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			List<String> picUrls = new ArrayList<>();
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			picUrls.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			addMicroProductBean.getProduct().getProductDescModel().setDescPicList(picUrls);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "主图中含有重复的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_addMicroProduct_011() {
		Logger.start(true,"参数校验-文描文字为空，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().getProductDescModel().setDescription(null);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "主图中含有重复的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_addMicroProduct_012() {
		Logger.start(true,"参数校验-文描文字部分长度超过700，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			String str = "nihao";
			for(int i=0;i<701;i++){
				str = str + i;
			}
			addMicroProductBean.getProduct().getProductDescModel().setDescription(str);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "主图中含有重复的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_018() {
		Logger.start(true,"参数校验-商品名称含有不宜发布的特殊字符“\\”，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setProductName("你好“\\”");
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "商品名称含有不宜发布的特殊字符“\\\\”");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_019() {
		Logger.start(true,"参数校验-无效的商品图片，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setPicUrls(null);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "无效的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_020() {
		Logger.start(true,"参数校验-商品图片无http，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			List<String> picUrls = new ArrayList<>();
			picUrls.add("//pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
			addMicroProductBean.getProduct().setPicUrls(picUrls);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "无效的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_addMicroProduct_021() {
		Logger.start(true,"参数校验-商品文描为空，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setProductDescModel(null);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "无效的商品图片");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_013() {
		Logger.start(true,"规格-启用规格价格小于等于0，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().getCatalogList().get(0).setPrice(-1);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "规格价格不能为0");
			addMicroProductBean.getProduct().getCatalogList().get(0).setPrice(0);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "规格价格不能为0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_014() {
		Logger.start(true,"规格-启用规格库存小于等于0，发布失败");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().getCatalogList().get(0).setStock(0);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("400", addmicroproductCall.getString("Code"), "库存必须大于0");
			addMicroProductBean.getProduct().getCatalogList().get(0).setStock(-1);
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("400", addmicroproductCall.getString("Code"), "库存必须大于0");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_015() {
		Logger.start(true,"敏感词校验-商品名称");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setProductName("全网唯一");
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "敏感词校验");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_016() {
		Logger.start(true,"敏感词校验-规格名称");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().getCatalogList().get(0).setCatalogName("全网唯一");
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "敏感词校验");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_addMicroProduct_017() {
		Logger.start(true,"敏感词校验-文描文字");
		try {
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().getProductDescModel().setDescription("全网唯一");
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("201", addmicroproductCall.getString("Code"), "敏感词校验");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_addMicroProduct_023() {
		Logger.start(true,"发布微店商品进入直播");
		try {
			List<Integer> liveIds = LiveCallService.createLivesInProcessAndInFuture(sellerId, sellerName, 2, 3);
			AddMicroProductBean addMicroProductBean = ProductManagerCallServiceV3.initAddmicroproductBean(sellerId);
			addMicroProductBean.getProduct().setLiveId(liveIds.get(0));
			addmicroproductCall.setData(addMicroProductBean);
			addmicroproductCall.callService();
			Logger.verifyEquals("200", addmicroproductCall.getString("Code"), "敏感词校验");
			String productId = addmicroproductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
			AddProductCallServiceV2.checkAddMicroProduct(productId,addMicroProductBean);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	//微店商品不校验物流

}